package com.cloud.shopping.seckill.controller;

import com.cloud.shopping.seckill.model.SeckillGoods;
import com.cloud.shopping.seckill.service.SeckillGoodsService;
import com.cloud.shopping.tool.RespResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author John.zhang
 * @version Id: SeckillOrderController, v 1.0 2021/1/8 11:01 ZhiYong Exp $
 */

@RestController
@RequestMapping(value = "/seckill/goods")
public class SeckillGoodsController {

    @Resource
    private SeckillGoodsService seckillGoodsService;

    /**
     * 根据活动查询秒杀商品集合
     *
     * @param acid acid
     * @return List
     */
    @GetMapping(value = "/act/{acid}")
    public RespResult<List<SeckillGoods>> actGoods(@PathVariable("acid") String acid) {
        List<SeckillGoods> seckillGoods = seckillGoodsService.actGoods(acid);
        return RespResult.ok(seckillGoods);
    }

    /**
     * 根据ID查询秒杀商品详情
     *
     * @param id id
     * @return SeckillGoods
     */
    @GetMapping(value = "/{id}")
    public RespResult<SeckillGoods> one(@PathVariable("id") String id) {
        SeckillGoods seckillGoods = seckillGoodsService.getById(id);
        return RespResult.ok(seckillGoods);
    }

}
